<template>
  <div class="live">
    <div class="left-view">
      <div class="top-content">
        <div v-if="list[leftIndex].showTitle=='show'" class="top-title">{{ list[leftIndex].title }}</div>
        <div v-if="list[leftIndex].showMore" class="top-more">
          <span>查看更多</span>
          <i class="el-icon-arrow-right"/>
        </div>
      </div>
      <!-- 无商品是默认展示 -->
      <ul v-if=" list[leftIndex].liveList.length<1">
        <li
          v-for="(item, index) in mockList"
          :key="index"
          :class="list[leftIndex].rowNum=='3'?'little':''"
          class="list-li"
        >
          <div class="img-box">
            <!-- <a :href="item.link"> -->
            <img :src="item.imgUrl" alt >
            <!-- </a> -->
          </div>
          <div class="list-info">
            <div class="title">{{ item.title }}</div>
            <div class="content">
              <i :class="item.status==true?'el-icon-s-data':'el-icon-video-camera-solid'"/>
              <span>{{ item.status==true?'直播中':'回看' }}</span>
            </div>
            <div class="price">{{ item.price=='0'?'免费':'￥'+item.price }}</div>
          </div>
        </li>
      </ul>
      <!-- 添加商品后展示 -->
      <ul v-if=" list[leftIndex].liveList.length>=1">
        <li
          v-for="(item, index) in list[leftIndex].liveList.slice(0,list[leftIndex].maxLength)"
          :key="index"
          :class="list[leftIndex].rowNum=='3'?'little':''"
          class="list-li"
        >
          <div class="img-box">
            <!-- <a :href="item.link"> -->
            <img :src="item.imgUrl" alt >
            <!-- </a> -->
          </div>
          <div class="list-info">
            <div class="title">{{ item.title }}</div>
            <div class="content">
              <i :class="item.status==true?'el-icon-s-data':'el-icon-video-camera-solid'"/>
              <span>{{ item.status==true?'直播中':'回看' }}</span>
            </div>
            <div class="price">{{ item.price=='0'?'免费':'￥'+item.price }}</div>
          </div>
        </li>
      </ul>
    </div>
    <div v-if="list[leftIndex].showRight" class="right-view">
      <div class="nav-title">知识商品设置</div>
      <div class="form-title">标题栏</div>
      <el-radio-group v-model="list[leftIndex].showTitle">
        <el-radio label="show">显示</el-radio>
        <el-radio label="unShow">不显示</el-radio>
      </el-radio-group>
      <div class="form-title">标题名称</div>
      <el-input v-model="list[leftIndex].title"/>
      <el-checkbox v-model="list[leftIndex].showMore" style="margin-top:10px;">显示"查看更多"入口</el-checkbox>
      <el-button icon="el-icon-plus" class="addUploadBtn" @click="liveDialog = true">添加直播</el-button>
      <div>
        <span>显示个数</span>
        <el-input v-model="list[leftIndex].maxLength" style="width:80px;"/>
      </div>
      <div class="form-hint">此页面最多展示前50个商品,已添加{{ list[leftIndex].liveList.length }}个</div>
      <div>
        <vuedraggable v-model="list[leftIndex].liveList" class="wrapper" animation="300">
          <transition-group>
            <div
              v-for="(item1, index1) in list[leftIndex].liveList"
              :key="index1"
              class="liveList"
            >
              <div class="list-img">
                <img :src="item1.imgUrl" alt >
              </div>
              <div class="list-title">{{ item1.title }}</div>
              <div class="list-tag">
                <span>{{ item1.tag }}</span>
                <i class="el-icon-delete" @click="liveListDelete(index1)"/>
              </div>
            </div>
          </transition-group>
        </vuedraggable>
      </div>
    </div>
    <!-- 知识商品 -->
    <liveDialog
      :dialog="liveDialog"
      @cancelClick="cancelClick"
      @confirmClick="multipleStudyConfirm"
    />
  </div>
</template>

<script>
import vuedraggable from 'vuedraggable'
import liveDialog from '../dialog/livedialog'
export default {
  components: {
    vuedraggable,
    liveDialog
  },
  props: ['list', 'leftIndex'],
  data() {
    return {
      mockList: [
        {
          imgUrl: '/src/assets/analyze_data/livestreaming.png',
          title: '直播-快速创建直播间',
          status: true,
          tag: '直播',
          price: '0'
        },
        {
          imgUrl: '/src/assets/analyze_data/livestreaming.png',
          title: '直播-快速创建直播间',
          status: false,
          tag: '直播',
          price: '20'
        },
        {
          imgUrl: '/src/assets/analyze_data/livestreaming.png',
          title: '直播-快速创建直播间',
          status: true,
          tag: '直播',
          price: '0'
        }
      ],
      liveDialog: false,
      rowNumOptions: [
        {
          value: '3',
          label: '3'
        },
        {
          value: '4',
          label: '4'
        }
      ],
      linkOptions: [
        {
          value: '微页面',
          label: '微页面'
        },
        {
          value: '知识商品',
          label: '知识商品'
        },
        {
          value: '商品分组',
          label: '商品分组'
        },
        {
          value: '自定义链接',
          label: '自定义链接'
        }
      ]
    }
  },
  methods: {
    // 删除商品列表事件
    liveListDelete(index) {
      this.list[this.leftIndex].liveList.splice(index, 1)
    },
    // 接收弹框取消事件
    cancelClick() {
      this.liveDialog = false
    },
    // 知识商品多选确认事件
    multipleStudyConfirm(data) {
      console.log(...data)
      this.liveDialog = false
      this.list[this.leftIndex].liveList.push(...data)
    }
  }
}
</script>

<style lang="scss" scoped>
.live {
  .left-view {
    cursor: move;
    .top-content {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 10px;
      .top-title {
        font-size: 20px;
        font-weight: bold;
      }
      .top-more {
        margin-left: auto;
        color: #999;
      }
    }
    ul {
      margin: 0;
      padding: 0;
      list-style: none;
      display: block;
      min-height: 20px;
      .list-li {
        // float: left;
        display: inline-block;
        width: 31%;
        margin: 1%;
        .img-box {
          height: 146px;
          img {
            border-radius: 5px;
            width: 100%;
            height: 100%;
          }
        }
        .list-info {
          padding: 10px;
          background-color: rgb(252, 249, 249);
          .title {
            font-size: 14px;
            font-weight: bold;
            color: #353535;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            margin-bottom: 5px;
          }
          .content {
            font-size: 12px;
            color: #7a7a7a;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            margin-top: 10px;
            margin-bottom: 30px;
          }
          .tag {
            font-size: 12px;
            width: 40px;
            border-radius: 5px;
            text-align: center;
            padding: 4px;
            background-color: rgb(38, 174, 236);
            color: #fff;
            margin: 10px 0;
          }
          .price {
          }
        }
      }
      .list-li.little {
        width: 31%;
        height: 165px;
      }
    }
  }
  .right-view {
    float: left;
    position: fixed;
    top: 176px;
    right: 4%;
    width: 16%;
    height: 806px;
    overflow: auto;
    z-index: 7;
    box-sizing: border-box;
    padding: 10px 20px;
    padding-bottom: 200px;
    color: #353535;
    font-size: 14px;
    font-family: 'PingFangSC-Medium';
    background: #f8f8f8;
    border: 1px solid #e5e5e5;
    border-radius: 5px;
    cursor: auto;
    .nav-title {
      height: 50px;
      font-weight: 800;
      line-height: 50px;
      border-bottom: 1px solid #eee;
    }
    .form-title {
      margin: 16px 0px;
      .sign {
        color: red;
      }
    }
    .form-hint {
      font-size: 12px;
      color: #999;
      margin: 14px 0;
    }
    .addUploadBtn {
      width: 100%;
      margin: 14px 0;
    }
    .liveList {
      padding: 10px;
      border: 1px dashed #b8b6b6;
      margin-bottom: 5px;
      display: flex;
      align-items: center;
      cursor: move;
      .list-img {
        width: 40px;
        height: 30px;
        margin-right: 10px;
        img {
          border-radius: 5px;
          width: 100%;
          height: 100%;
        }
      }
      .list-title {
        width: 100px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }
      .list-tag {
        color: #7a7a7a;
        margin-left: auto;
        i {
          margin-left: 20px;
          cursor: pointer;
        }
      }
    }
  }
  @media screen and (max-width: 1600px) {
    .left-view {
      ul {
        .list-li {
          .img-box {
            height: 86px;
          }
          .list-info {
            .content {
              margin: 10px 0;
            }
          }
        }
      }
    }
    .right-view {
      right: 1%;
      width: 20%;
      padding: 10px;
      padding-bottom: 250px;
      height: 668px;
    }
  }
}
</style>
